AddCSLuaFile( "cl_init.lua" )
AddCSLuaFile( "shared.lua" )
include( 'shared.lua' )

function ENT:SpawnFunction( ply, tr )
	if ( !tr.Hit ) then return end
	local SpawnPos = tr.HitPos + tr.HitNormal * 16
	local ent = ents.Create("sent_spaceanon_nebula")
	ent:SetPos( SpawnPos )
	ent:Spawn()
	ent:Activate()
	return ent
end

function ENT:Initialize()
	self.Entity:SetModel( "models/Combine_Helicopter/helicopter_bomb01.mdl" )
	self.Entity:PhysicsInit(SOLID_VPHYSICS)
	self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
	self.Entity:SetSolid(SOLID_VPHYSICS)
	local phys = self.Entity:GetPhysicsObject()
	if (phys:IsValid()) then
		phys:Wake()
		phys:EnableMotion(false)
		phys:EnableCollisions(true)
	end
	self.Entity:SetColor(0,0,0,255)
	self.Power = math.random(5000,10000)
end

function ENT:Think()
	nebula = ents.FindInSphere(self.Entity:GetPos(),1512)
	for k,v in pairs (nebula) do
		if v:IsValid() then
			local str = v:GetClass()
			if (not string.find(str, "physgun_beam")) and
				(not string.find(str, "predicted_viewmodel")) and
				(not (string.find(str, "func_") and (str ~= "func_physbox"))) and
				(not string.find(str, "info_")) and
				(not string.find(str, "point_")) and
				(not string.find(str, "path_")) and
				(not string.find(str, "node")) and
				(not string.find(str, "sent_spaceanon")) and 
				(not string.find(str, "env_")) then
				local Current = VectorRand()*self.Power
				local phys = v:GetPhysicsObject()
				if(phys:IsValid()) then
					if v:GetMoveType() == 6 then
//						phys:ApplyForceCenter(phys:GetMass()*Current)
					else
//						v:SetVelocity(Current)
					end
				end
			end
		end
	end
	self.Entity:NextThink(CurTime()+2)
end
